package com.eastfair.venueservice.controller;

import com.eastfair.venueservice.entity.ReportVenueDrawingAuditHistory;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditHistorySaveDTO;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditHistoryUpdateDTO;
import com.eastfair.venueservice.dto.ReportVenueDrawingAuditHistoryPageQuery;
import com.eastfair.venueservice.service.ReportVenueDrawingAuditHistoryService;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import com.eastfair.boot.controller.SuperController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.echo.core.EchoService;
import com.eastfair.core.base.R;
import com.eastfair.venueservice.vo.ReportVenueDrawingAuditHistoryVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import com.eastfair.annotation.annotation.security.PreAuth;

import com.eastfair.boot.request.PageParams;
import com.eastfair.core.context.ContextUtil;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 一键报馆图纸审核记录历史
 * </p>
 *
 * @author dq
 * @date 2022-09-16
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/reportVenueDrawingAuditHistory")
@Api(value = "ReportVenueDrawingAuditHistory", tags = "一键报馆图纸审核记录历史")
@PreAuth(replace = "venueservice:reportVenueDrawingAuditHistory:")
public class ReportVenueDrawingAuditHistoryController extends SuperController<ReportVenueDrawingAuditHistoryService, Long, ReportVenueDrawingAuditHistory, ReportVenueDrawingAuditHistoryPageQuery, ReportVenueDrawingAuditHistorySaveDTO, ReportVenueDrawingAuditHistoryUpdateDTO> {

    @Resource
    private EchoService echoService;

    @Resource
    private ReportVenueDrawingAuditHistoryService reportVenueDrawingAuditHistoryService;

    @Override
    public void handlerResult(IPage<ReportVenueDrawingAuditHistory> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }

    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ReportVenueDrawingAuditHistory> reportVenueDrawingAuditHistoryList = list
                .stream()
                .map((map) -> ReportVenueDrawingAuditHistory.builder().build())
                .collect(Collectors.toList());
        return R.success(baseService.saveBatch(reportVenueDrawingAuditHistoryList));
    }

    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ReportVenueDrawingAuditHistoryPageQuery> params) {
        ReportVenueDrawingAuditHistoryPageQuery pageQuery = params.getModel();
        //分页处理
        if(ContextUtil.getProjectId()!=null){
            pageQuery.setProjectId(ContextUtil.getProjectId());
        }
    }

    /**
     * 图纸分类审核历史ID查询图纸历史列表.
     *
     * @param reportVenueDrawingCategoryAuditHistoryId the report venue drawing category audit history id
     * @return the r
     */
    @GetMapping("/categoryAuditHistoryId/{reportVenueDrawingCategoryAuditHistoryId}")
    public R<List<ReportVenueDrawingAuditHistoryVO>> queryByReportVenueDrawingCategoryAuditHistoryId(@PathVariable("reportVenueDrawingCategoryAuditHistoryId")
                                                                                                     Long reportVenueDrawingCategoryAuditHistoryId) {
        log.info("queryByReportVenueDrawingCategoryAuditHistoryId - 图纸分类审核历史ID查询图纸历史列表, reportVenueDrawingCategoryAuditHistoryId={}", reportVenueDrawingCategoryAuditHistoryId);
        List<ReportVenueDrawingAuditHistoryVO> list
                = reportVenueDrawingAuditHistoryService.listByReportVenueDrawingCategoryAuditHistoryId(reportVenueDrawingCategoryAuditHistoryId);
        return R.successDef(list);
    }
}
